﻿using System;
using System.Runtime.InteropServices;

using OpenTK.Graphics.OpenGL;
using OpenTK;

namespace GLSL
{
    static class GLSL
    {
        static public readonly bool HasGL3;
        static public readonly bool SupportsShaders;

        static GLSL()
        {
            string version = GL.GetString(StringName.Version);

            if (version.Contains("Compatibility"))
            {
                HasGL3 = false;
            }

            string ext = "";
            if (HasGL3 == false)
            {
                ext = GL.GetString(StringName.Extensions);
            }
            else
            {
                int extC;
                GL.GetInteger(GetPName.NumExtensions, out extC);
                for (int q = 0; q < extC; q++) ext += GL.GetString(StringName.Extensions, q) + " ";
            }

            if (ext.Contains("vertex_shader") && ext.Contains("fragment_shader"))
            {
                SupportsShaders = true;
            }
            else
            {
                SupportsShaders = false;
            }
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct Byte4
    {
        public byte R, G, B, A;

        public Byte4(byte[] input)
        {
            R = input[0];
            G = input[1];
            B = input[2];
            A = input[3];
        }

        public uint ToUInt32()
        {
            byte[] temp = new byte[] { this.R, this.G, this.B, this.A };
            return BitConverter.ToUInt32(temp, 0);
        }

        public override string ToString()
        {
            return this.R + ", " + this.G + ", " + this.B + ", " + this.A;
        }
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct Vertex
    {
        public Vector3 Postion;
        public Vector2 TextureUV;
        public Vector3 Normal;
        //public Byte4 Color;

        public readonly static int Stride = Marshal.SizeOf(default(Vertex));
    }     
}
